package com.demo.project_template.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.demo.project_template.entity.Post;
import com.demo.project_template.service.PostService;
import com.demo.project_template.vo.response.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import javafx.geometry.Pos;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 用户帖子 前端控制器
 * </p>
 *
 * @author 杨玉龙
 * @since 2024-08-20 11:48:57
 */
@Api(tags = "动态（帖子）")
@RestController
@RequestMapping("/post")
public class PostController {
    @Resource
    private PostService postService;

    @ApiOperation(value = "分页查询动态")
    @GetMapping(value = "/page")
    public R<IPage<Post>> page(@RequestParam Integer pageNo,
                               @RequestParam Integer pageSize,
                               @RequestParam Long userId) {
        Page<Post> result = postService.page(new Page<>(pageNo, pageSize));
        postService.handlePost(result.getRecords(), userId);
        return R.success(result);
    }

    @ApiOperation(value = "添加动态")
    @PostMapping(value = "/add")
    public R<?> add(@RequestBody Post post) {
        postService.save(post);
        return R.success();
    }

    @ApiOperation(value = "删除动态")
    @DeleteMapping(value = "/id")
    public R<?> delete(@RequestParam Long id) {
        postService.removeById(id);
        return R.success();
    }
}
